package cn.tedu.movie.mapper;

import cn.tedu.movie.entity.Movie;
import cn.tedu.movie.entity.SessionVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SessionMapper {
    @Select("SELECT h.layout FROM session s\n" +
            "LEFT JOIN hall h ON s.hall_id=h.id\n" +
            "WHERE s.id=#{id}")
     String layout(Integer id) ;
    @Select("select price from `session` where id = #{id}")
    Integer price(int id);
    @Select("SELECT s.id id,s.price price,c.name `cinema`,\n" +
            "h.name `hall`,m.name `movie`,s.start_date startDate\n" +
            "FROM `movie` m, `session` s ,hall h ,cinema c \n" +
            "WHERE m.id=s.movie_id AND s.hall_id=h.id AND h.cinema_id=c.id\n" +
            "order by s.id\n"+
            "limit #{pageNum},#{limit}")
    List<SessionVo> sessionlist(Integer pageNum, Integer limit);
    @Select("SELECT COUNT(*)\n" +
            "FROM `movie` m, `session` s ,hall h ,cinema c \n" +
            "WHERE m.id=s.movie_id AND s.hall_id=h.id AND h.cinema_id=c.id")
    Integer sessionCount();
    @Select("SELECT COUNT(*) FROM session WHERE hall_id=#{hallId}\n" +
            "AND sess=#{sessId} AND `date`=#{dateId} ")
    int check(Integer hallId, Integer sessId, Integer dateId);
    @Insert("insert into session values(null,#{startDate}," +
            "#{hallId},#{movieId},#{price},#{sessId},#{dateId})")
    Integer insertSession(SessionVo sessionVo);
    @Delete("delete from `session` where id=#{id}")
    void deleteById(Integer id);
    @Select("SELECT m.name\n" +
            "FROM `session` s,`movie` m\n" +
            "WHERE s.movie_id=m.id\n" +
            "AND s.id=#{id}")
    String backstageSelect(Integer id);
    @Update("update session set movie_id=#{movieId} where id=#{id}")
    int updateSession(Integer movieId, Integer id);
}
